package com.bs.rss.utype;

import java.util.Date;
import java.util.List;

import com.bs.rss.common.enums.EnumPagine;
import com.bs.rss.common.model.data.RssType;
import com.bs.rss.common.model.data.User;
import com.bs.rss.common.utils.JsonReturn;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;

public class RssTypeController extends Controller{


	public void add(){
		
		boolean f = false;
		Ret t = JsonReturn.re.saveFail(EnumPagine.subfail);
		
		String typename = getPara("typename","");
		
		RssType rt = new RssType();
		
		User u = getSessionAttr("currentuser");
		
		rt.setTypename(typename);
		rt.setUserId(u.getId()+"");
		rt.setCtime(new Date());
		
		f = rt.save();
		
		if(f){t = JsonReturn.re.saveOk(EnumPagine.ok, rt);}
		
		renderJson(t);
		
	}
	
	public void upd(){
		

		boolean f = false;
		Ret t = JsonReturn.re.saveFail(EnumPagine.subfail);
		
		String typename = getPara("typename","");
		Integer id = getParaToInt("tid", 0);
		
		RssType rt = RssType.dao.findById(id);
		
		rt.setTypename(typename);
		
		f = rt.update();
		
		if(f){t = JsonReturn.re.saveOk(EnumPagine.ok, rt);}
		
		renderJson(t);
	}
	
	public void del(){
		
	}
	
	public void types(){
		
		User u = getSessionAttr("currentuser");
		
		List<RssType> l = RssType.dao.findbyUser(u.getId());
		
		renderJson(Ret.ok("list",l));
	}
	public void types1(){
		User u = getSessionAttr("currentuser");
		Page<RssType> lc = RssType.dao.PfindbyUser(getParaToInt("pageIndex", 1), getParaToInt("pageSize", 10), u.getId());
		renderJson(JsonReturn.re.PageOk(lc.getTotalRow(), lc, EnumPagine.ok));
	}
}
